package edu.cebanc.spring.biblioteca.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import edu.cebanc.spring.biblioteca.domain.Editorial;

@Repository("editorialesDAO")
public class EditorialesDAOImpl implements EditorialesDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Editorial> listEditoriales() {
		// TODO Auto-generated method stub
		return (List<Editorial>)sessionFactory.getCurrentSession().createCriteria(Editorial.class).list();
	}

	@Override
	public void saveEditorial(Editorial editorial) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().saveOrUpdate(editorial);
	}

	@Override
	public Editorial getEditorial(int id) {
		// TODO Auto-generated method stub
		return (Editorial)sessionFactory.getCurrentSession().load(Editorial.class, id);
	}

	@Override
	public void deleteEditorial(Editorial editorial) {
		// TODO Auto-generated method stub
		sessionFactory.getCurrentSession().delete(editorial);
	}

}
